package com.machine.filling.function.splish;

import android.Manifest;
import android.content.Intent;
import android.os.Environment;
import android.support.annotation.NonNull;
import android.view.View;

import com.machine.filling.MyApp;
import com.machine.filling.R;
import com.machine.filling.Test.TestCommon;
import com.machine.filling.base.SimpleBaseActivity;
import com.machine.filling.db.DBUtils;
import com.machine.filling.db.dao.CardTempDao;
import com.machine.filling.db.dao.ClientInfoDao;
import com.machine.filling.db.dao.ExceptionOrderDao;
import com.machine.filling.db.dao.GunInfoDao;
import com.machine.filling.db.dao.TempOrderDao;
import com.machine.filling.db.greendao.DaoMaster;
import com.machine.filling.db.modle.AdModle;
import com.machine.filling.db.modle.GunInfoModle;
import com.machine.filling.function.init.activity.MainFrameActivity;
import com.machine.filling.util.Common;
import com.machine.filling.util.FileUtils;
import com.machine.filling.util.PermissionUtil;
import com.tencent.bugly.Bugly;
import com.tencent.bugly.crashreport.CrashReport;

import java.io.File;

/**
 * Created by LENOVO on 2017/12/16.
 */

public class SplishActivity extends SimpleBaseActivity {


    @Override
    public View initViews() {
        return null;
    }

    @Override
    public void initDatas() {
        checkStoragePremission();
        startActivity(new Intent(mContext, MainFrameActivity.class));
        finish();
    }

    /**
     * 检查 存储权限
     */
    private void checkStoragePremission() {
        PermissionUtil.getInstance().checkPermissions(mActivity, Manifest.permission.READ_EXTERNAL_STORAGE,
                Common.PERMIASSION_REQ_STORGE, new PermissionUtil.PermissionListener() {
                    @Override
                    public void permissionAllowed() {
                        setDateBaseFile();
                    }

                    @Override
                    public void goSettingPermission() {
                        PermissionUtil.getInstance().goToSetPermission(mActivity, getResources().getString(R.string.notice_premission_external_storage));
                    }
                });
    }

    /**
     * 权限获取成功后,创建数据库
     */
    private void setDateBaseFile() {
        boolean isDbCreate = FileUtils.isFileExist("OIL_CLIENT.db","oilClient/" + getPackageName(),true);
        if (!isDbCreate){
            MyApp.getInstance().setDatabase();
        }
        finish();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        PermissionUtil.getInstance().onActivityResult(requestCode, resultCode, data);
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        PermissionUtil.getInstance().onRequestPermissionResult(requestCode, permissions, grantResults, Common.PERMIASSION_REQ_STORGE);
    }
}
